package com.lesso.cyg.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.cyg.sunflower.domain.repository.EmployeeAttendanceRuleRelRepository;
import com.lesso.cyg.sunflower.infra.assembler.EmployeeAttendanceRuleRelAssembler;
import com.lesso.cyg.sunflower.pojo.dto.EmployeeAttendanceRuleRelDTO;
import com.lesso.cyg.sunflower.pojo.dto.EmployeeAttendanceRuleRelQueryDTO;
import com.lesso.cyg.sunflower.model.EmployeeAttendanceRuleRel;
import org.springframework.stereotype.Service;

/**
 * EmployeeAttendanceRuleRelDomainService
 *
 * @author cyg
 * @since 2025-07-02
 */
@Service
public class EmployeeAttendanceRuleRelDomainService {

    private final EmployeeAttendanceRuleRelRepository employeeAttendanceRuleRelRepository;

    public EmployeeAttendanceRuleRelDomainService(EmployeeAttendanceRuleRelRepository employeeAttendanceRuleRelRepository) {
        this.employeeAttendanceRuleRelRepository = employeeAttendanceRuleRelRepository;
    }

    public Integer save(EmployeeAttendanceRuleRelDTO dto) {
        return employeeAttendanceRuleRelRepository.save(EmployeeAttendanceRuleRelAssembler.INSTANCE.dtoToEntity(dto));
    }

    public void deleteById(Long id) {
        employeeAttendanceRuleRelRepository.removeById(id);
    }

    public Integer update(EmployeeAttendanceRuleRelDTO dto) {
        return employeeAttendanceRuleRelRepository.update(EmployeeAttendanceRuleRelAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<EmployeeAttendanceRuleRelDTO> page(EmployeeAttendanceRuleRelQueryDTO dto) {
        // 这里需要实现具体的查询逻辑，根据 dto 中的条件查询
        Page<EmployeeAttendanceRuleRel> entityPage = new Page<>(dto.getPage().getCurrent(), dto.getPage().getSize());
        Page<EmployeeAttendanceRuleRelDTO> dtoPage = new Page<>();
        dtoPage.setRecords(EmployeeAttendanceRuleRelAssembler.INSTANCE.entityListToDtoList(entityPage.getRecords()));
        return dtoPage;
    }
}